package com.unbook.controller;

import com.qiniu.util.Auth;
import com.unbook.entity.ResponseVo;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/qiniu")
public class QiniuController {
    @Value("${qiniu.accessKey}")
    String accessKey;
    @Value("${qiniu.secretKey}")
    String secretKey;
    @Value("${qiniu.storeName}")
    String storeName;
    @Value("${qiniu.signKey}")
    String signKey;

    /**
     * 获取上传token的方法
     * @return
     */
    @GetMapping("/getToken")
    public ResponseVo<String> getUpToken(){
        Auth auth = Auth.create(accessKey,secretKey);
        String token = auth.uploadToken(storeName);
        return ResponseVo.success(token);
    }
}
